﻿//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//    Crolengi, this program (a part of program) is gameengine based on C++\Directx
//    Copyright (C) 2008 Pashinin Anton Alekseevich (Crol)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//    (INCLUDING NEGLIGENCE OR OTHERWISE) 
//    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
//    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//    Contacts: 
//    Mail: crolengi@gmail.com
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once
#ifndef  Camera_Manager_h
#define  Camera_Manager_h

#include "include\\Utils\\Console.h"
#include "include\\Utils\\Timer.h"
#include "..\\import\\CRLEngi_strings_lib\\CRLEngi_strings.h"
#include "..\\import\\param_trees_lib\\param_trees.h"
#include "include\\Objects\\CCamera.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
/////   :: КЛАСС МЕНЕДЖЕРА КАМЕР ::
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class CLREngi_Camera_Manager{
protected:
	typedef struct NODE_TYP{       // структура нашего растения %)
		unsigned int id;                          // Идентификатор
		CLREngi_Camera  *Camera;
        DynamicRow      Parameters;                  // Параметры камеры
		NODE_TYP        *next;                       // Указатель на следующий узел списка
		NODE_TYP        *prev;                       // Указатель на предыдущий узел списка
	   }NODE,*NODE_PTR;
public:
unsigned int            LOADED_cameras; // число камер
NODE_PTR                CurrientCamera; // номер текущей
NODE_PTR                head;           // начало списка вамер
D3DXMATRIXA16          *matWorld;       // копия мировой 
D3DMATERIAL9            Material;

CLREngi_Console        *Console;

Timer   keyTimer;


D3DXVECTOR2 g_ptCurrentMousePosit,g_ptLastMousePosit;

public:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Чтение параметров из структуры
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	bool          LoadFromRow(char *file){
		CRLEngi_string a;
		a = file;
		DynamicRow row;
		row.iLoadFromFile(a);
		SetupFromRow(&row);
		return true;	
	}

 	void          SetupFromRow(DynamicRow   *row){
        // настройка материалов и текстур для отображения камер
		Material.Emissive.r = 1;
		Material.Emissive.g = 1;
		Material.Emissive.b = 1;
		Material.Emissive.a = 1;

		Material.Ambient.r = 1;
		Material.Ambient.g = 1;
		Material.Ambient.b = 1;
		Material.Ambient.a = 1;
       
		// подготовка к анализу структуры
		int id1 = 0, count,id2 = 0;
		CRLEngi_string CamName;
		CamName = "";
		id1 = (*row).iLookId("_CAMERAS_");
        count =  (*row).iCountKnots(id1) + (*row).iCountParams(id1);
		if (id1>0)
			if (count>0){
			   id2     = (*row).TopId(id1);
			   CamName = (*row).iLookName(id2);
               CreateNewCamera(CamName,row,false);
			   for (int i=1;i<count;i++){
				   id2     = (*row).NextId(id2);
				   CamName = (*row).iLookName(id2);
                   CreateNewCamera(CamName,row,false);
			     }//for
			   }//if
			SetCamera(1);
	}//void

	D3DXMATRIX get_currient_ViewPos(){
		 D3DXMATRIX mat,mat2;
		  D3DXMatrixIdentity(&mat);
		 D3DXMatrixLookAtRH(&mat,&head->next->next->next->Camera->Position,
			                     &head->next->next->next->Camera->Look,
			                     &head->next->next->next->Camera->Up);
         D3DXMatrixInverse(&mat,NULL,&head->next->next->next->Camera->CamView);
		 D3DXMatrixTranslation(&mat2,head->next->next->next->Camera->Position.x,
									head->next->next->next->Camera->Position.y,
									head->next->next->next->Camera->Position.z);
		//D3DXMatrixMultiply(&mat,&mat,&mat2);
		 //D3DXMatrixTranslation(&mat,CurrientCamera->Camera->Position.x,CurrientCamera->Camera->Position.y,CurrientCamera->Camera->Position.z);
	     return mat;
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Создание камеры из параметров структыры
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    unsigned int  CreateNewCamera(CRLEngi_string CamName,DynamicRow   *row,bool MakeCurrient){

		    // Вставка узла в конец списка
			NODE_PTR new_node = NULL;
			NODE_PTR curr;

			if (head == NULL) //Список пуст
				 curr = NULL; //(*head);
			else
			     curr = (head);

			// Создание нового узла
			// В C++ здесь используется оператор new
			new_node = (NODE_PTR)malloc(sizeof(NODE));
			//Заполняем поля
			LOADED_cameras      += 1;
			(new_node->Camera) = new CLREngi_Camera(matWorld);
			 new_node->Camera->Camera_setup(CamName,row);

			 CRLEngi_string buffer;
			buffer = "[+] Camera:  ";
			buffer += CamName.getChars();
			Console->AddText(buffer,0);
			
			new_node->Parameters = *row;
			new_node->id         = LOADED_cameras;
			new_node->next       = NULL; // Лучше это делать всегда;
			  if (MakeCurrient) CurrientCamera = new_node;
			// в данном случае наш узел будет
			// последним в списке, так что это
			// просто необходимо
			// Поиск конца списка и вставка
			if (curr == NULL){ //Список пуст
				(head) = new_node;
				return(new_node->id);
				}//if
			else{
				while(curr->next != NULL) curr  = curr->next;
				curr->next = new_node;
				new_node->prev = curr;
				return(new_node->id);
				}//else
		}//func
	CLREngi_Camera* NewCamera(CRLEngi_string CamName,bool MakeCurrient){
		    // Вставка узла в конец списка
			NODE_PTR new_node = NULL;
			NODE_PTR curr;

			if (head == NULL) //Список пуст
				 curr = NULL; //(*head);
			else
			     curr = (head);

			// Создание нового узла
			// В C++ здесь используется оператор new
			new_node = (NODE_PTR)malloc(sizeof(NODE));
			//Заполняем поля
			LOADED_cameras      += 1;
			(new_node->Camera) = new CLREngi_Camera(matWorld);
			// new_node->Camera->Camera_setup(CamName,row);

			 CRLEngi_string buffer;
			buffer = "[+] Camera:  ";
			buffer += CamName.getChars();
			Console->AddText(buffer,0);
			
			//new_node->Parameters = *row;
			new_node->id         = LOADED_cameras;
			new_node->next       = NULL; // Лучше это делать всегда;
			  if (MakeCurrient) CurrientCamera = new_node;
			// в данном случае наш узел будет
			// последним в списке, так что это
			// просто необходимо
			// Поиск конца списка и вставка
			if (curr == NULL){ //Список пуст
				(head) = new_node;
				return(new_node->Camera);
				}//if
			else{
				while(curr->next != NULL) curr  = curr->next;
				curr->next = new_node;
				new_node->prev = curr;
				return(new_node->Camera);
				}//else
	
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Выбор текущей камеры
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	bool          SetCamera(unsigned int id){
		
		NODE_PTR curr;
        curr = head;
		while (true){
			if (curr->id == id){
						CurrientCamera = curr;
                        return true;
			            }//if
			if(curr->next == NULL) break;
			curr = curr->next;
		 }//while
			
		 return false;
		}//bool

	void          NextCamera(){
		int keytime = (int)(keyTimer.getElapsedTimeMilliSeconds()/60);
        if(keytime>5)
        {
			keyTimer.getCurrentTime();
		   if (CurrientCamera->id<LOADED_cameras)
                  SetCamera(CurrientCamera->id+1);
		       else
			      SetCamera(1);
		}

	
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Уничтожение камеры
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    bool	      DestroyCamera(unsigned int id){

			NODE_PTR curr_ptr = head, prev_ptr = head;
			if (curr_ptr == NULL) //Список пуст
				return(false);
			// Обход списка и поиск удаляемого узла
			while(curr_ptr && curr_ptr->id != id){
				// Сохраняем положение в списке
				curr_ptr = curr_ptr->next;
				} // while

			if(curr_ptr==NULL)
				return(false);	//Узел не найден

			if (curr_ptr == head){ //Узел в начале списка
				head = (head)->next; // Обновляем заголовок
				}
			 else{
				// Обновляем указатель
				curr_ptr->prev->next = curr_ptr->next;
				}//else
			curr_ptr->Parameters.fresh();
			free(curr_ptr); // Освобождаем память
			return(true);
	}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Получение матриц камеры
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void          SetupCurrientMatrix(LPDIRECT3DDEVICE9 *Device){
	    CurrientCamera->Camera->Get_Matrix(Device);	
	    }
	void          SetupEffects(){
		    	
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Отображение текущей камеры
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void          RenderCurrientCamera(LPDIRECT3DDEVICE9 *Device){
	    
		CurrientCamera->Camera->Get_PrimitiveDrawing(Device);
	    }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Отображение всех камер (кроме текущей)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void          RenderAllCamera(LPDIRECT3DDEVICE9 *Device){

		(*Device)->SetMaterial( &Material );

		 NODE_PTR curr;
         curr = head;
		while (true){
			if (CurrientCamera!=curr)
            curr->Camera->Get_PrimitiveDrawing(Device);
			if(curr->next == NULL) break;
			curr = curr->next;
		 }


	    }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Полное движение камеры по вектору
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void          CurrientCameraMoveFull(D3DXVECTOR3 move){
	
		CurrientCamera->Camera->CameraMoveFull(move);
	    }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////  Получить id текущей камеры
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	int             GetCurrientIDint(){
	return CurrientCamera->id;
	}
    CRLEngi_string  GetCurrientIDstr(){
		CRLEngi_string a;
		int one;
		one= CurrientCamera->id;
		a = one;
	return a;
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Обработка мыши
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void          MouseInput( HWND g_hWnd ,bool GMousing)
{
	//if(!(*Console).visible)
	//{
	//
	// Get mouse input...
	//
    //*GMousing = true;
	POINT mousePosit,mouseZero;
	GetCursorPos( &mousePosit );
	
	mouseZero.x = 1024/2;
    mouseZero.y = 768/2;

	ScreenToClient( g_hWnd, &mouseZero );
	ScreenToClient( g_hWnd, &mousePosit );
	if(!(*Console).visible)
	{

	g_ptCurrentMousePosit.x = (float)mousePosit.x;
    g_ptCurrentMousePosit.y = (float)mousePosit.y;


	D3DXMATRIX matRotation;
	D3DXVECTOR3 CamLook;
    
	CRLEngi_string  currCameraName;
	currCameraName = CurrientCamera->Camera->CameraName ;

    if( GMousing)
    {
	  // если камера не контроллера персонажа тогда мы можем ее двигать
	  if (currCameraName != "CC"){

		int nXDiff = (g_ptCurrentMousePosit.x - g_ptLastMousePosit.x);
        int nYDiff = -(g_ptCurrentMousePosit.y - g_ptLastMousePosit.y);
     
        
        if( nYDiff != 0 ) // up-down
		{
			D3DXMatrixRotationAxis( &matRotation, &CurrientCamera->Camera->Right, D3DXToRadian((float)nYDiff / 3.0f));
			CamLook.x = CurrientCamera->Camera->Look.x-CurrientCamera->Camera->Position.x;
			CamLook.y = CurrientCamera->Camera->Look.y-CurrientCamera->Camera->Position.y;
			CamLook.z = CurrientCamera->Camera->Look.z-CurrientCamera->Camera->Position.z;
			D3DXVec3TransformCoord( &CamLook, &CamLook, &matRotation );
			CurrientCamera->Camera->Look.x = CamLook.x+CurrientCamera->Camera->Position.x;
			CurrientCamera->Camera->Look.y = CamLook.y+CurrientCamera->Camera->Position.y;
			CurrientCamera->Camera->Look.z = CamLook.z+CurrientCamera->Camera->Position.z;

			//D3DXVec3TransformCoord( &CurrientCamera->Camera->Up,   &CurrientCamera->Camera->Up,   &matRotation );
		}

		if( nXDiff != 0 ) // left-right
		{
			D3DXMatrixRotationAxis( &matRotation, &D3DXVECTOR3(0,1,0), D3DXToRadian((float)nXDiff / 3.0f) );
			CamLook.x = CurrientCamera->Camera->Look.x-CurrientCamera->Camera->Position.x;
			CamLook.y = CurrientCamera->Camera->Look.y-CurrientCamera->Camera->Position.y;
			CamLook.z = CurrientCamera->Camera->Look.z-CurrientCamera->Camera->Position.z;
			D3DXVec3TransformCoord( &CamLook, &CamLook, &matRotation );
			CurrientCamera->Camera->Look.x = CamLook.x+CurrientCamera->Camera->Position.x;
			CurrientCamera->Camera->Look.y = CamLook.y+CurrientCamera->Camera->Position.y;
			CurrientCamera->Camera->Look.z = CamLook.z+CurrientCamera->Camera->Position.z;
			//D3DXVec3TransformCoord( &CurrientCamera->Camera->Up,   &CurrientCamera->Camera->Up,   &matRotation );
		}
	  }// if not CC camera
	  else{
	    int nXDiff = (g_ptCurrentMousePosit.x - g_ptLastMousePosit.x);
        int nYDiff = -(g_ptCurrentMousePosit.y - g_ptLastMousePosit.y);
     
        
       /* if( nYDiff != 0 ) // up-down
		{
			D3DXMatrixRotationAxis( &matRotation, &D3DXVECTOR3(1,0,0), D3DXToRadian((float)nYDiff / 3.0f));
			CamLook.x = -(CurrientCamera->Camera->Look.x-CurrientCamera->Camera->Position.x);
			CamLook.y = -(CurrientCamera->Camera->Look.y-CurrientCamera->Camera->Position.y);
			CamLook.z = -(CurrientCamera->Camera->Look.z-CurrientCamera->Camera->Position.z);
			D3DXVec3TransformCoord( &CamLook, &CamLook, &matRotation );
			CurrientCamera->Camera->Position.x = -CamLook.x+CurrientCamera->Camera->Look.x;
			CurrientCamera->Camera->Position.y = -CamLook.y+CurrientCamera->Camera->Look.y;
			CurrientCamera->Camera->Position.z = -CamLook.z+CurrientCamera->Camera->Look.z;

			//D3DXVec3TransformCoord( &CurrientCamera->Camera->Up,   &CurrientCamera->Camera->Up,   &matRotation );
		}*/

		if( nXDiff != 0 ) // left-right
		{
			D3DXMatrixRotationAxis( &matRotation, &D3DXVECTOR3(0,1,0), D3DXToRadian((float)nXDiff / 3.0f) );
			CamLook.x = -CurrientCamera->Camera->Look.x+CurrientCamera->Camera->Position.x;
			CamLook.y = -CurrientCamera->Camera->Look.y+CurrientCamera->Camera->Position.y;
			CamLook.z = -CurrientCamera->Camera->Look.z+CurrientCamera->Camera->Position.z;
			D3DXVec3TransformCoord( &CamLook, &CamLook, &matRotation );
			CurrientCamera->Camera->Position.x = CamLook.x+CurrientCamera->Camera->Look.x;
			CurrientCamera->Camera->Position.y = CamLook.y+CurrientCamera->Camera->Look.y;
			CurrientCamera->Camera->Position.z = CamLook.z+CurrientCamera->Camera->Look.z;
			//D3DXVec3TransformCoord( &CurrientCamera->Camera->Up,   &CurrientCamera->Camera->Up,   &matRotation );
		}
	  
	  
	  }
    }

    g_ptLastMousePosit.x = g_ptCurrentMousePosit.x;
    g_ptLastMousePosit.y = g_ptCurrentMousePosit.y;

	}// if ! console.visible
	else
	     { 
		//if (GMousing)
		  (*Console).MouseInput(0,mousePosit);
		// else
		  //(*Console).MouseInput(2,mousePosit);
		 }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Обработка нажатия клавиш
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void          KeyInput(  HWND hwnd ,float  Time){

		if((*Console).visible)
	     {
			
			 
			    
		 }
		else{

	//
	// Get keyboard input...
	//
		Time= (float)(Time/60);
		if (Time<0.05)Time=0.05 ;

		


	unsigned char keys[256];
	GetKeyboardState( keys );
    D3DXVECTOR3 tmppos,N;
	
	N.x =  CurrientCamera->Camera->Look.x - CurrientCamera->Camera->Position.x;
	N.y =  CurrientCamera->Camera->Look.y - CurrientCamera->Camera->Position.y;
	N.z =  CurrientCamera->Camera->Look.z - CurrientCamera->Camera->Position.z;
	D3DXVec3Normalize(&N,&N);
    
	D3DXVECTOR3 tmpLook  = N;
	D3DXVECTOR3 tmpRight = CurrientCamera->Camera->Right;
    bool pr=false;

   // если камера не контроллера персонажа тогда мы можем ее двигать
  if (CurrientCamera->Camera->CameraName != "CC"){

	if ((keys[0x57]  & 0x80))
	{   
		
		
		  tmppos = CurrientCamera->Camera->Position;	
		  tmppos.x  -= (tmpLook.x *-CurrientCamera->Camera->MoveSpeed)*Time;
		  tmppos.z  -= (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time;

		  CurrientCamera->Camera->Position.x -= (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time;
		  CurrientCamera->Camera->Position.z -= (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time;

		  CurrientCamera->Camera->Look.x -= (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time;
		  CurrientCamera->Camera->Look.z -= (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time;
		
		//tmpLook  = CurrientCamera->Camera->Look;

	}

	if((keys[0x53]  & 0x80))
	{	
		  tmppos = CurrientCamera->Camera->Position;
	      tmppos.x += (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time;
		  tmppos.z += (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time;

		  CurrientCamera->Camera->Position.x += (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time;  
		  CurrientCamera->Camera->Position.z += (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time; 

		  CurrientCamera->Camera->Look.x += (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time;
		  CurrientCamera->Camera->Look.z += (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time;
		 


		//tmpLook  = CurrientCamera->Camera->Look;

	
	}
	if ((keys[0x41]  & 0x80))
	{	tmppos = CurrientCamera->Camera->Position;
		tmppos.x -= (tmpRight.x*CurrientCamera->Camera->MoveSpeed*Time);
		tmppos.z -= (tmpRight.z*CurrientCamera->Camera->MoveSpeed*Time);
		CurrientCamera->Camera->Position.x  += (tmpRight.x*CurrientCamera->Camera->MoveSpeed*Time); 
		CurrientCamera->Camera->Position.z  += (tmpRight.z*CurrientCamera->Camera->MoveSpeed*Time); 

		CurrientCamera->Camera->Look.x  += (tmpRight.x*CurrientCamera->Camera->MoveSpeed*Time); 
		CurrientCamera->Camera->Look.z  += (tmpRight.z*CurrientCamera->Camera->MoveSpeed*Time); 

	}
	if((keys[0x44]  & 0x80))
	{	tmppos = CurrientCamera->Camera->Position;
		tmppos.x += (tmpRight.x*CurrientCamera->Camera->MoveSpeed)*Time;
		tmppos.z += (tmpRight.z*CurrientCamera->Camera->MoveSpeed)*Time;
		CurrientCamera->Camera->Position.x -= (tmpRight.x*CurrientCamera->Camera->MoveSpeed)*Time;
		CurrientCamera->Camera->Position.z -= (tmpRight.z*CurrientCamera->Camera->MoveSpeed)*Time;

		CurrientCamera->Camera->Look.x -= (tmpRight.x*CurrientCamera->Camera->MoveSpeed)*Time;
		CurrientCamera->Camera->Look.z -= (tmpRight.z*CurrientCamera->Camera->MoveSpeed)*Time;

	}

	if( keys[0xC0] & 0x80 )
	 { 
		// keys[VK_NUMPAD1] = false;
		// (*Console).Timer01.getCurrentTime();	
		 //(*Console).Timer02.getCurrentTime();
		 (*Console).Hide_unHide();// = true;
		 //(*Console).KeyTimersUpdate();	 
	 }


	if( keys[VK_LSHIFT] & 0x80 )
	  { tmppos = CurrientCamera->Camera->Position;
		tmppos.x  -= (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time*10;
		tmppos.z  -= (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time*10;
		tmppos.y  -= (tmpLook.y*-CurrientCamera->Camera->MoveSpeed)*Time*10;

		CurrientCamera->Camera->Position.x -= (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time*10;
		CurrientCamera->Camera->Position.z -= (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time*10;
		CurrientCamera->Camera->Position.y -= (tmpLook.y*-CurrientCamera->Camera->MoveSpeed)*Time*10;

		CurrientCamera->Camera->Look.x     -= (tmpLook.x*-CurrientCamera->Camera->MoveSpeed)*Time*10;
		CurrientCamera->Camera->Look.z     -= (tmpLook.z*-CurrientCamera->Camera->MoveSpeed)*Time*10;
		CurrientCamera->Camera->Look.y     -= (tmpLook.y*-CurrientCamera->Camera->MoveSpeed)*Time*10;

 
	}
  }
	if( keys[VK_TAB] & 0x80 )
	 { 
        NextCamera();         
 
	 }

  
}
	
}//void
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void           AnalyzeCommand(CRLEngi_string  Command){

	   /// теперь анализ команды
	   CRLEngi_string  C1,C2;
	   Command.DivideTwoParameters(&C1,&C2);	   

	   if ((C1=="camera.set")||(C1=="Camera.Set")){
		   CRLEngi_string  CC;
		   CC  = "Currient camera was changed to: camera № ";		  
		   SetCamera(C2.toInt());
		   CC += (int)CurrientCamera->id;
		   Console->AddText(CC,3);
	       }
	   else
	   if (C1=="camera.next"){
		   CRLEngi_string  CC;
		   CC  = "Currient camera was changed to: camera № ";		   
		   NextCamera();
		   CC += (int)CurrientCamera->id;
		   Console->AddText(CC,3);
	       }
	   else
	   if (C1=="camera.speed"){
		   CRLEngi_string  CC;
		   CC  = "Currient camera speed was changed to: ";		   
		   CurrientCamera->Camera->MoveSpeed = C2.toFloat();
		   CC += C2.toFloat();
		   Console->AddText(CC,3);
	       }
      //....
	  
	
}//void

public:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                     КОНСТРУКТОР
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	CLREngi_Camera_Manager(D3DXMATRIXA16* GMatrix,CLREngi_Console   *Cnsl){ 
		CurrientCamera = NULL;
		LOADED_cameras = 0;
		head = NULL;
		matWorld = GMatrix;
		Console = Cnsl ;
		keyTimer.intialize();
	    keyTimer.getCurrentTime();
	};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                       ДЕСТРУКТОР
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	virtual ~CLREngi_Camera_Manager(){};
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#endif 